<?php
@ob_start();
@session_start();

include("../connect/connect.php");
include("../function/config.php");
include("../function/thaidate.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-</title>
<link rel="stylesheet" href="stylereport.css" type="text/css" />
<link rel="shortcut icon" href="../image/Letter-T.ico" />
<style type="text/css" media="print">
input{
	display:none;
}
</style>

</head>
<?php
	$dQuery = mysql_query("SELECT min(sale_datetime) as sale_datetime FROM sale_report");
	$dnQuery = mysql_fetch_array($dQuery);
	
	$lQuery = mysql_query("SELECT * FROM table_status");
	$lNum = mysql_num_rows($lQuery);

?>
<body <?php if($lNum=='0' && $dnQuery['sale_datetime']!=""){ echo "onload=\"window.print()\""; } ?>>
<?php
//แสดงรายงานเครื่องดื่มแอลกอฮอล์
$Query = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty, sum(sale_report.sale_service) as sale_service FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '3' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<font size="5"><strong><?php echo $report['header'];?></strong></font><br>
<font size="5"><strong>รายงานการขายแยกตามประเภทสินค้า</strong></font><br><br>
<font size="4"><strong>
<?php
	if($lNum>'0'){
		echo "<font color=\"red\">กรุณาเช็คบิลให้ครบทุกโต๊ะก่อนค่ะ</font>";
	}else if($dnQuery['sale_datetime']!=""){
		echo "ประจำ".ThaiDate($dnQuery['sale_datetime']);
?>
</strong></font><br>
<font size="3"><strong>พนักงานขาย : <?php echo $_SESSION["user_name"]." ".$_SESSION["user_surname"]; ?></strong></font>
<h2>เครื่องดื่มแอลกอฮอล์</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="12%">ราคาขาย</td>
<td width="10%">ค่าบริการ</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$num1 = 0;
while($row1 = mysql_fetch_array($Query)) {
	$num1++;
?>
<tr>
<td align="center"><?php echo $num1; ?></td>
<td align="left" style="padding-left:10px"><?php echo $row1['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo "".number_format($row1['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row1['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php echo number_format($row1['sale_price']*$row1['sale_qty'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $salediscont = $row1['sale_service']; echo number_format($salediscont, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px">
<?php
$presale = $row1['sale_price']*$row1['sale_qty'];
$sale_discount = $presale + $salediscont;
echo number_format($sale_discount, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal1=$strTotal1+$sale_discount;
}
?>
<tfoot>
<?php if($num1>='1'){ ?>
  <tr>
    <td colspan="6" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo "".number_format($strTotal1, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="7" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>

<?php
//แสดงรายงานมิกเซอร์
$Query1 = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty, sum(sale_report.sale_discount) as sale_discount, sum(sale_report.sale_service) as sale_service FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '2' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<h2>มิกเซอร์</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="12%">ราคาขาย</td>
<td width="10%">ค่าบริการ</td>
<td width="10%">ส่วนลด</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$num2 = 0;
while($row2 = mysql_fetch_array($Query1)) {
	$num2++;
?>
<tr>
<td align="center"><?php echo $num2 ?></td>
<td align="left" style="padding-left:10px"><?php echo $row2['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo number_format($row2['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row2['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $total2 = $row2['sale_price']*$row2['sale_qty']; echo number_format($total2, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $service2 = $row2['sale_service']; echo number_format($service2, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $discount2 = $row2['sale_discount']; echo number_format($discount2, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount2 = ($total2+$service2)-$discount2;
echo number_format($sale_discount2, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal2=$strTotal2+$sale_discount2;
}
?>
<tfoot>
<?php if($num2>='1'){ ?>
  <tr>
    <td colspan="7" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo number_format($strTotal2, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="8" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>

<?php
//แสดงรายงานอาหาร
$Query3 = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty, sum(sale_report.sale_discount) as sale_discount, sum(sale_report.sale_service) as sale_service FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '1' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<h2>อาหาร</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="12%">ราคาขาย</td>
<td width="10%">ค่าบริการ</td>
<td width="10%">ส่วนลด</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$num3 = 0;
while($row3 = mysql_fetch_array($Query3)) {
	$num3++;
?>
<tr>
<td align="center"><?php echo $num3; ?></td>
<td align="left" style="padding-left:10px"><?php echo $row3['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo number_format($row3['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row3['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $total3 = $row3['sale_price']*$row3['sale_qty']; echo number_format($total3, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $service3 = $row3['sale_service']; echo number_format($service3, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $discount3 = $row3['sale_discount']; echo number_format($discount3, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount3 = ($total3+$service3)-$discount3;
echo number_format($sale_discount3, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal3=$strTotal3+$sale_discount3;
}
?>
<tfoot>
<?php if($num3>='1'){ ?>
  <tr>
    <td colspan="7" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo "".number_format($strTotal3, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="8" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>

<?php
//แสดงรายงานมินิบาร์
$Query4 = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty, sum(sale_report.sale_service) as sale_service FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '4' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<h2>มินิบาร์</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="12%">ราคาขาย</td>
<td width="10%">ค่าบริการ</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$num4 = 0;
while($row4 = mysql_fetch_array($Query4)) {
	$num4++;
?>
<tr>
<td align="center"><?php echo $num4; ?></td>
<td align="left" style="padding-left:10px"><?php echo $row4['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo "".number_format($row4['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row4['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $total4 = $row4['sale_price']*$row4['sale_qty']; echo number_format($total4, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $service4 = $row4['sale_service']; echo number_format($service4, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount4 = $total4+$service4;
echo number_format($sale_discount4, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal4=$strTotal4+$sale_discount4;
}
?>
<tfoot>
<?php if($num4>='1'){ ?>
  <tr>
    <td colspan="6" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo "".number_format($strTotal4, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="7" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>


<?php
//แสดงห้องพัก
$Query5 = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty, sum(sale_report.sale_discount) as sale_discount FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '6' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<h2>ห้องพัก</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="12%">ราคาขาย</td>
<td width="10%">ส่วนลด</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$row6 = 0;
while($row5 = mysql_fetch_array($Query5)) {
	$num5++;
?>
<tr>
<td align="center"><?php echo $num5; ?></td>
<td align="left" style="padding-left:10px"><?php echo $row5['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo number_format($row5['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row5['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $total5 = $row5['sale_price']*$row5['sale_qty']; echo number_format($total5, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $discount5 = $row5['sale_discount']; echo number_format($discount5, 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount5 = $total5-$discount5;
echo number_format($sale_discount5, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal5=$strTotal5+$sale_discount5;
}
?>
<tfoot>
<?php if($num5>='1'){ ?>
  <tr>
    <td colspan="6" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo number_format($strTotal5, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="7" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>


<?php
//แสดงอื่นๆ
$Query6 = mysql_query("SELECT product.prod_name as prod_name, product.prodtype_id as prodtype_id ,sale_report.sale_price as sale_price, sum(sale_report.sale_qty) as sale_qty FROM product,sale_report WHERE product.prod_id = sale_report.prod_id AND product.prodtype_id = '5' GROUP BY sale_report.prod_id,sale_report.sale_price ORDER BY sum(sale_report.sale_qty) DESC");
?>
<h2>อื่นๆ</h2>
<table class="listorder">
  <thead>
<tr>
<td width="1%">ลำดับ</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="8%">จำนวน</td>
<td width="13%">ราคารวม</td>
</tr>
  </thead>
<?php
$num6 = 0;
while($row6 = mysql_fetch_array($Query6)) {
	$num6++;
?>
<tr>
<td align="center"><?php echo $num6; ?></td>
<td align="left" style="padding-left:10px"><?php echo $row6['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo number_format($row6['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $row6['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount6 = $row6['sale_price']*$row6['sale_qty'];
echo number_format($sale_discount6, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal6=$strTotal6+$sale_discount6;
}
?>
<tfoot>
<?php if($num6>='1'){ ?>
  <tr>
    <td colspan="4" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo number_format($strTotal6, 2,'.',','); ?></td>
	</tr>
<?php } else { ?>
  <tr>
    <td colspan="5" align="center">ไม่มีรายการ</td>
	</tr>
<?php } ?>
</tfoot>
</table>

<div class="endtotal">รวมทั้งหมด <?php echo "".number_format($strTotal1+$strTotal2+$strTotal3+$strTotal4+$strTotal5+$strTotal6, 2,'.',',')." บาท"; ?></div>
<div style="padding-top: 20px">
<input type="button" name="endsale" id="endsale" value="ปิดการขาย" onclick="javascript:if(confirm('ยืนยันปิดการขาย')==true){window.location='report2.php?action=endsale';}" ></div>
<?php } else {
echo "<font color=\"red\">ยังไม่มีรายการขายของวันนี้ค่ะ</font>";
}
?>
</body>

</html>
